﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MasterPage : System.Web.UI.MasterPage
{
    Operation operation = new Operation();　//声明业务类
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["username"] != null)
        {
            //Login1.Visible = false;
            welcome.Text = "你好，" + Session["username"];
            welcome.Visible = true;
            loginOut.Visible = true;
            UserManager.Visible = true;
            Button1.Visible = false;
            Button2.Visible = false;
            int lyNum = operation.SelectNote(Session["userid"].ToString(),false).Tables[0].Rows.Count;
            if (lyNum > 0)
            {
                liuyan.NavigateUrl = "~/UserBackGround/Default.aspx";
                liuyan.Text = "你有" + lyNum + "条未读留言";
                Session.Add("lyNum", lyNum);
            }
            else
            {
                liuyan.Visible = false;
            }
        }
        //time.Text = DateTime.Now.ToString("yyyy年MM月dd日\tdddd", new System.Globalization.CultureInfo("zh-cn"));
    }
    protected void registerUser(object sender, EventArgs e)
    {
        Response.Redirect("~/UserRegister/Register.aspx");
    }
    protected void forgotPassword(object sender, EventArgs e)
    {
        Response.Redirect("~/ForgotPassword.aspx");
    }
    protected void LoginButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/UserLogin.aspx");
    }
    protected void loginOut_Click(object sender, EventArgs e)
    {
        Session.Clear();
        welcome.Visible = false;
        loginOut.Visible = false;
        UserManager.Visible = false;
        Button1.Visible = true;
        Button2.Visible = true;
        //Login1.PasswordRequiredErrorMessage = "";
        //Login1.Visible = true;
        Response.Redirect("~/Default.aspx");
    }
    protected void UserManager_Click(object sender, EventArgs e)
    {
        if (Session["username"] == null)
        {
            //Response.Write("<script language=javascript>alert('请先登录!');</script>");
            WebMessageBox.Show("请先登录!", "~/UserLogin.aspx");
        }
        else
        {
            Response.Redirect("~/UserBackGround/Default.aspx");
        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        if (Session["username"] == null)
        {
            //Response.Write("<script language=javascript>alert('请先登录!');</script>");
            String svrname = HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
            String port = ":" + HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
            string url = "http://" + svrname + port;
            WebMessageBox.Show("请先登录!", url+"/UserLogin.aspx");
        }
        else
        {
            Response.Redirect("~/UserBackGround/InfoAdd.aspx");
        }
    }
}
